package com.example.demo.bizhan.reflect;

import org.junit.Test;

import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;

import static java.lang.System.*;

/**
 * @description: xxx
 * @time: 2020/10/27 14:32
 * @author: baojinlong
 **/
public class IntrospectorDemoTest {

    @Test
    public void test02() throws Exception {
        Student student = new Student();
        PropertyDescriptor age = new PropertyDescriptor("age", Student.class);
        Method writeMethod = age.getWriteMethod();
        writeMethod.invoke(student, 30);
        Method readMethod = age.getReadMethod();
        Object invoke = readMethod.invoke(student);
        out.println(invoke);
        out.println(age.getPropertyType());
    }

    @Test
    public void test01() throws Exception {
        BeanInfo beanInfo = Introspector.getBeanInfo(Student.class);
        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
        for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
            out.println(propertyDescriptor.getName());
        }
    }
}
